package com.example.exp05_server_aidl_remote_service;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.os.RemoteException;
import android.widget.Toast;

public class MyService extends Service {
    public static final String TAG = "MyService";

    public MyService() {
    }

    @Override
    public void onCreate() {
        super.onCreate();
        Toast.makeText(this, "onCreate() executed", Toast.LENGTH_SHORT).show();
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        Toast.makeText(this, "onStartCommand() executed", Toast.LENGTH_SHORT).show();
        return super.onStartCommand(intent, flags, startId);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        Toast.makeText(this, "onDestroy() executed", Toast.LENGTH_SHORT).show();
    }

    @Override
    public IBinder onBind(Intent intent) {
        return myBinder;
    }
    /**
     * 最好在一开始创建好对应的AIDL后再Build，后续重新Build可能会出很多问题
     * 如果上一个aidl文件改废了，怎么build都生成不了java文件，那就删掉重新添加一个
     *
     * 很重要的一个细节是在写完aidl文件后记得要在Build中先clean Project再rebuild project
     * 不然aidl的接口文件无法转化成Java的Interface文件，下面的语句就没办法正常实现
     */
    MyAIDLService.Stub myBinder = new MyAIDLService.Stub() {
        @Override
        public void basicTypes(int anInt, long aLong, boolean aBoolean, float aFloat, double aDouble, String aString) throws RemoteException {
        }

        @Override
        public double plus(double numb1, double numb2) throws RemoteException {
            return numb1+numb2;
        }

        @Override
        public double sub(double numb1, double numb2) throws RemoteException {
            return numb1-numb2;
        }

        @Override
        public double multiply(double numb1, double numb2) throws RemoteException {
            return numb1*numb2;
        }
    };

}